package com.bian.springboot.Controller;

import com.bian.springboot.entities.Department;
import com.bian.springboot.entities.Employee;
import com.bian.springboot.mapper.DepartmentMapper;
import com.bian.springboot.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author bianpengfei
 * @create 2019-02-01 19:36
 **/
@RestController
public class DeptController {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Autowired
    private EmployeeMapper employeeMapper;

    @GetMapping("/dept/{id}")
    public Department getDepartment(@PathVariable("id") Integer id){
        return departmentMapper.getDeptId(id);
    }

    @GetMapping("/dept")
    public Department addDepartment(Department department) {
        departmentMapper.addDept(department);
        return department;
    }

    @GetMapping("/emp/{id}")
    public Employee getEmployee(@PathVariable("id") Integer id) {
        return employeeMapper.getEmployeeId(id);
    }

    @GetMapping("/emp")
    public Employee insertEmp(Employee employee) {
        return employeeMapper.insertEmp(employee) > 0 ? employee : null;
    }

}
